package si.yun.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import si.yun.entity.*;
import si.yun.service.TeachersService;
import si.yun.utils.JsonData;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description TODO 教师功能
 * @Date $ 2021/8/23 21:34
 * @return $
 */
@RestController
@RequestMapping("/Teacher")
@PropertySource("classpath:config.properties")
public class TeachersController {
    @Autowired
    private TeachersService service;

    @Value("${path1}")
    private String path1;

    /**
      *  @Decriptron 视频查询
     * @Date:2021/8/30 19:12
     * @Return:si.yun.utils.JsonData
     */
    @GetMapping("/selVideo")
    public JsonData selVideo(){
        Map<Object, Object> ObjectMap = service.selVideo();
        return ObjectMap!=null?JsonData.buildSuccess(ObjectMap):JsonData.buildError("服务器出错了");
    }

    /**
      *  @Decriptron 待处理业务
     * @Date:2021/8/23 21:34
     * @Return:java.util.Map<java.lang.Object,java.lang.Object>
     */
    @GetMapping("/selChuLi")
    public JsonData selChuLi(){
        Map<Object, Object> ObjectMap = service.selChuLi();
        return ObjectMap!=null?JsonData.buildSuccess(ObjectMap):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查看已上架数量
     * @Date:2021/8/23 21:34
     * @Return:java.util.Map<java.lang.Object,java.lang.Object>
     */
    @GetMapping("/selShelves")
    public JsonData selShelves(){
        Map<Object, Object> objectObjectMap = service.selShelves();
        return objectObjectMap!=null?JsonData.buildSuccess(objectObjectMap):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查看今天新增人数
     * @Date:2021/8/23 21:34
     * @Return:int
     */
    @GetMapping("/selToday")
    public JsonData selToday(){
        int Today = service.selToday();
        return Today!=-1?JsonData.buildSuccess(Today):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查看昨日新增人数
     * @Date:2021/8/23 21:34
     * @Return:int
     */
    @GetMapping("/selYesterDay")
    public JsonData selYesterDay(){
        int YesterDay = service.selYesterDay();
        return YesterDay!=-1?JsonData.buildSuccess(YesterDay):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查看本月新增人数\
     * @Date:2021/8/23 21:34
     * @Return:int
     */
    @GetMapping("/selMonth")
    public JsonData selMonth(){
        int month = service.selMonth();
        return month!=-1?JsonData.buildSuccess(month):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查看全部新增人数
     * @Date:2021/8/23 21:34
     * @Return:int
     */
    @GetMapping("/selAll")
    public JsonData selAll(){
        int all = service.selAll();
        return all!=-1?JsonData.buildSuccess(all):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查看七日内新增人数
     * @Date:2021/8/23 21:33
     * @Return:int
     */
    @GetMapping("/selWeek")
    public JsonData selWeek(){
        int i = service.selWeek();
        return i!=-1?JsonData.buildSuccess(i):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 按照时间查询
     * @Date:2021/8/23 21:33
     * @Return:si.yun.utils.JsonData
     */
    @PostMapping("/selDate")
    public JsonData selTimeOrder(String datetime){
        List<Integer> i = service.selTimeOrder(datetime);
        return i!=null?JsonData.buildSuccess(i):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查询table表格
     * @Date:2021/8/23 21:33
     * @Return:si.yun.utils.JsonData
     */
    /*
    @PostMapping("/selectTable")
    public JsonData selectTable(String name,Integer price,Integer course) {
        List<Map<String, Object>> stringObjectMap = service.selectTable(name,price,course);
        return stringObjectMap!=null?JsonData.buildSuccess(stringObjectMap):JsonData.buildError("服务器出错了");
    }
    */
    @PostMapping("/selectTable")
    public JsonData selectTable(String name,Integer price,Integer course,Integer course_id) {
        List<Map<String, Object>> stringObjectMap = service.selectTable(name,price,course,course_id);
        return stringObjectMap!=null?JsonData.buildSuccess(stringObjectMap):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron
     * @Date:2021/8/23 21:33
     * @Return:
     */
    @GetMapping("/selectTable1")
    public JsonData selectTable1() {
        List<Map<String, Object>> stringObjectMap = service.selectTable1();
        return stringObjectMap!=null?JsonData.buildSuccess(stringObjectMap):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 上传公共方法
     * @Date:2021/8/29 15:46
     * @Return:java.util.Map
     */
    public Map upload(HttpServletRequest request, MultipartFile file,SyMicrocircleImg img){
        Map<String, Object> map = new HashMap<>();
        String name = file.getOriginalFilename();
        long time = System.currentTimeMillis();
        String newName = time + name.substring(name.lastIndexOf("."));
        String path = TeachersController.class.getResource("/").getPath() + File.separator + "template" + File.separator + "upload";
        File file2 = new File(path + "/" + newName);
        if (!file2.isDirectory()) {
            file2.mkdirs();
        }
        try {
            file.transferTo(file2);
        } catch (IllegalStateException | IOException e) {
            e.printStackTrace();
        }
        img.setPictureUrl(newName);
        map.put("code",0);
        map.put("msg", "");
        map.put("data", file2);
        map.put("image", "/upload/" + newName);
        return map;
    }

    /**
      *  @Decriptron 上传图片
     * @Date:2021/8/23 21:33
     * @Return:java.util.Map<java.lang.String,java.lang.Object>
     */
    @PostMapping("/insertImg")
    public JsonData insertImg(HttpServletRequest request, MultipartFile file, SyMicrocircleImg img) {
        Map upload = upload(request, file, img);
        int insert8 = service.insertImg(img);
        return upload!=null?JsonData.buildSuccess(upload):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 上传视频
     * @Date:2021/8/23 21:32
     * @Return:java.util.Map<java.lang.String,java.lang.Object>
     */
    @PostMapping("/insertVideo")
    public JsonData insertVideo(HttpServletRequest request, MultipartFile file, SyMicrocircleImg img) {
        Map upload = upload(request, file, img);
        int insert8 = service.insertVoide(img);
        return upload!=null?JsonData.buildSuccess(upload):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查询日志
     * @Date:2021/8/23 21:32
     * @Return:java.util.Map<java.lang.Object,java.lang.Object>
     */
    @GetMapping("/selProductRizhi")
    public  JsonData selProductRizhi() {
        List<Map<Object,Object>> objectObjectMap = service.selProductRizhi();
        return objectObjectMap!=null?JsonData.buildSuccess(objectObjectMap):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 查询评论
     * @Date:2021/8/27 16:31
     * @Return:java.util.List<java.util.Map<java.lang.Object,java.lang.Object>>
     */
    @GetMapping("/selComments")
    public  JsonData selComments() {
        List<Map<Object, Object>> maps = service.selComments();
        return maps!=null?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }
    /**
      *  @Decriptron 修改商品详情
     * @Date:2021/9/7 16:12
     * @Return:si.yun.utils.JsonData
     */
  /*  public  JsonData IntTable() {
        List<Map<Object, Object>> maps = service.IntTable();
        return maps!=null?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }*/

    @PostMapping("/uplTea")
    public JsonData uplTea(List<SyCourseClass> list) {
        int upload = service.uplTea(list);
        System.out.println(upload);
        return upload!=-1?JsonData.buildSuccess(upload):JsonData.buildError("服务器出错了");
    }
    @PostMapping("/InsBohui")
    public JsonData insBohui(String result,String details) {
        int maps = service.insBohui(result, details);
        System.out.println(maps);
        return maps!=-1?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }
    @PostMapping("/selMicroRing")
    public JsonData selMicroRing() {
        List<Map<Object, Object>> maps = service.selMicroRing();
        System.out.println(maps);
        return maps!=null?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }

    @GetMapping("/ProductCategory")
    public JsonData selProductCategory(){
        List<Map<String, Object>> maps = service.selProductCategory();
        return maps!=null?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }




}
